<!-- 品牌配置 -->
<template>
    <div >
        <div class="table-page-search-wrapper">
            <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 17 }">
                 <a-form-item label="进入排行榜的最大排名">
                    <a-input v-model="config.maxRankNumber" placeholder="请输入进入排行榜的最大排名" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="签到获得积分数量">
                    <a-input v-model="config.checkInCoinNumber" placeholder="请输入签到获得积分数量" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="新用户奖励积分">
                    <a-input v-model="config.registerCoinNumber" placeholder="请输入新用户奖励积分" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="绑定手机号奖励积分">
                    <a-input v-model="config.bindPhoneCoinAward" placeholder="请输入绑定手机号奖励积分" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="下级注册奖励积分">
                    <a-input v-model="config.sonUserCoinAward" placeholder="请输入下级注册奖励积分" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="填写花店名称奖励积分">
                    <a-input v-model="config.addShopNameCoinAward" placeholder="请输入填写花店名称奖励积分" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="商城下单奖励积分比例">
                    <a-input v-model="config.buyShopCoinAward" placeholder="请输入商城下单奖励积分比例" suffix="%" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="直推下级商城下单奖励积分比例">
                    <a-input v-model="config.sonUserBuyShopCoinAward" placeholder="请输入直推下级商城下单奖励积分比例" suffix="%" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="单个身份证号最大可实名次数">
                    <a-input v-model="config.maxRealNameAuthCount" placeholder="请输入单个身份证号最大可实名次数" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="首页商品一行展示最大个数">
                    <a-input v-model="config.homeGoodsMaxNumByLine" placeholder="请输入首页商品一行展示最大个数" allow-clear></a-input>
                </a-form-item>
                 <a-form-item label="首页商品单个区域最大商品展示个数">
                    <a-input v-model="config.homeGoodsMaxNumByCate" placeholder="请输入首页商品单个区域最大商品展示个数" allow-clear></a-input>
                </a-form-item>
                <a-form-item  v-bind="formItemLayoutWithOutLabel">
                    <a-button type="primary" @click="updateConfig">立即修改</a-button>
                </a-form-item>
            </a-form>
        </div>
    </div>
</template>

<script>
import { queryBrandConfig , updateBrandConfig , updateBrandConfigKey , queryCheckInCoinNumber , updateCheckInCoinNumber } from '@/api/brand';
import { uploadBrandFile } from '@/api/power';
export default {
    data () {
        return {
            brandId: this.global.brandId,
            config: {
                maxRankNumber: '', // 进入排行榜的最大排名
                checkInCoinNumber: '', // 签到获得积分数量
                registerCoinNumber: '', // 新用户奖励积分
                bindPhoneCoinAward: '', // 绑定手机号奖励积分
                sonUserCoinAward: '', // 下级注册奖励积分
                addShopNameCoinAward: '', // 填写花店名称奖励积分
                buyShopCoinAward: '', // 商城下单奖励积分比例
                sonUserBuyShopCoinAward: '', // 直推下级商城下单奖励积分比例
                maxRealNameAuthCount: '', // 单个身份证号最大可实名次数
                homeGoodsMaxNumByLine: '', // 首页商品一行展示最大个数
                homeGoodsMaxNumByCate: '', // 首页商品单个区域最大商品展示个数
            },
            formItemLayoutWithOutLabel: {
                wrapperCol: {
                    xs: { span: 24, offset: 0 },
                    sm: { span: 20, offset: 6 },
                },
            },
            checkInCoinNumber: '', // 签到积分数量
            showSIMGUpload: false,
            confirmLoading: false,
            serviceImgList: [],
            serviceImgfile: {},
        };
    },
    created(){
        this.getConfig();
        this._queryCheckInCoinNumber();
    },
    methods: {
        getConfig(){
            let _this = this
            const params = {
                'brandId':_this.brandId,
                'configKey':'', // 配置字段名称
                'isGroup':1, // 是否分组,0:否,1:是
            }
            queryBrandConfig(params)
            .then(res=>{
                if(res.success){
                    if(res.data.length > 0){
                        _this.config = res.data[0]
                        _this.config.buyShopCoinAward = _this.config.buyShopCoinAward * 100;
                        _this.config.sonUserBuyShopCoinAward = _this.config.sonUserBuyShopCoinAward * 100;
                    }
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 修改品牌信息
        async updateConfig(){
            let _this = this
            if(!_this.brandId){
                _this.$message.warning('请先选择品牌！')
                return
            }
            const params = {
                'maxRankNumber': _this.config.maxRankNumber,
                'checkInCoinNumber':_this.config.checkInCoinNumber,
                'registerCoinNumber':_this.config.registerCoinNumber,
                'bindPhoneCoinAward':_this.config.bindPhoneCoinAward,
                'sonUserCoinAward':_this.config.sonUserCoinAward,
                'addShopNameCoinAward':_this.config.addShopNameCoinAward,
                'buyShopCoinAward':_this.config.buyShopCoinAward,
                'sonUserBuyShopCoinAward':_this.config.sonUserBuyShopCoinAward,
                'maxRealNameAuthCount':_this.config.maxRealNameAuthCount,
                'homeGoodsMaxNumByLine': _this.config.homeGoodsMaxNumByLine,
                'homeGoodsMaxNumByCate': _this.config.homeGoodsMaxNumByCate,
            }
            if(_this.config.checkInCoinNumber != _this.checkInCoinNumber){
                _this._updateCheckInCoinNumber();
            }
            for (const key in params) {
                var data = params[key];
                if(key == 'buyShopCoinAward' || key == 'sonUserBuyShopCoinAward'){
                    data = params[key] / 100;
                }
                var pam = {
                    'brandId': _this.brandId,
                    'configKey': key,
                    'configValue': data,
                }
                await updateBrandConfigKey(pam)
                if(key == 'homeGoodsMaxNumByCate'){
                    _this.$notification['success']({
                        message: '提示',
                        description: '修改成功',
                        duration: 8,
                    })
                    _this.getConfig()
                }
            }
        },
        // 获取签到积分奖励配置
        _queryCheckInCoinNumber(){
            let _this = this;
            queryCheckInCoinNumber({'brandId': _this.brandId})
            .then(res => {
                if(res.success){
                    _this.checkInCoinNumber = res.data;
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            }) 
        },
        // 修改签到积分数量
        _updateCheckInCoinNumber(){
            let _this = this;
            const params = {
                'brandId': _this.brandId,
                'awardCoin': _this.config.checkInCoinNumber,
            }
            updateCheckInCoinNumber(params)
            .then(res => {
                if(res.success){
                    _this._queryCheckInCoinNumber();
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
    }
}

</script>
<style scoped>

</style>